const express = require('express');
const app = express();
const port = 3330;
const path = require('path');
const redis = require('./redis');
app.use(express.static('build'))
app.use(express.static('assets'))
app.use("/bottle", function (req, res) {
    console.log(req.query);
    if (!req.query.user) {
        return res.json({ code: 0, msg: "信息不完整" });
    }
    if (req.query.type && (["male", "female", "all"].indexOf(req.query.type) === -1)) {
        return res.json({ code: 0, msg: "类型错误" });
    }
    redis.pick(req.query.user, function (result) {
        console.log(result)
        switch (result.code) {
            case 0:
                return res.status(400).json({
                    code: 0,
                    msg: result.msg
                })
            case 1:
                if (Object.keys(result.msg).length === 0) return res.status(400).json({
                    code: 0,
                    msg: '没有找到！'
                })
                return res.status(200).json({
                    code: 1,
                    msg: result.msg
                })

            default:
                break;
        }

    });
});

app.listen(port, () => {
    console.log(`App is listening at http://localhost:${port} !`);
});